﻿@{
    ViewBag.Title = "我的消息";
    Layout = "~/Views/Shared/_LayoutFore.cshtml";
    var member = Session["CurrentUser"] as LY.Entity.U_Member;
}

@section script{
    <script src="~/Content/assets/plugins/xjgrid/xjgrid.js"></script>
    <script type="text/javascript">
        ;
        (function (window, undefined, $) {
            $(document).ready(function () {
                // var mid = $('#hidMid').val();
                var gridopt = {
                    url: options.listUrl,
                    colModel: [
                        { display: '编号', name: 'Id', width: "5%", sortable: true, hide: true, align: 'left', iskey: true },
                        { display: '', name: 'Name', width: "85%", sortable: true, hide: false, align: 'left', process: talkAboutWith },
                        { display: '', name: 'MemberId', width: "5%", sortable: true, hide: true, align: 'left', hide: true },
                        { display: '', name: 'MessageMemberId', width: "5%", sortable: true, hide: true, align: 'left', hide: true },
                        { display: '', name: 'AddTime', width: "14%", sortable: true, hide: true, align: 'center' },
                        { display: '', name: 'Status', width: "14%", sortable: true, hide: true, align: 'center' },
                        { display: '', name: 'Message', width: "50%", sortable: true, hide: true, align: 'center' },
                        { display: '', name: 'Id', width: "14%", sortable: true, align: 'center', process: processOp }
                    ],
                    sortname: "Id",
                    sortorder: "DESC",
                    title: false,
                    rp: 5,
                    usepager: true,
                    showcheckbox: false
                };
                var xjgrid = new xjGrid("gridlist", gridopt);

                function talkAboutWith(value, cell) {
                    var ops = [];
                    ops.push("<div><a onclick=\"util.Flag('", cell[0], "')\" style='text-decoration:underline;color:blue;cursor:pointer;'>标识已读</a></br>");
                    ops.push("<b style='color:red;'>&nbsp您</b>&nbsp与&nbsp<b style='color:red'>", cell[1], "</b>&nbsp的会话", "&nbsp&nbsp&nbsp", cell[4], "</br>", cell[6], "&nbsp&nbsp&nbsp", cell[5] == 0 ? "<b style='color:green'>【您有新的私信】</b>" : "", "</br></div>");
                    ops.push("<div id='Detail_", cell[0], "' style='display:none;background-color:white'></div>");
                    ops.push("<div id='Reply_", cell[0], "' style='display:none;'><textarea cols='81' rows='5' placeholder='请输入回复内容...'></textarea><br />");
                    ops.push("<input type='button' onclick=\"util.Submit('", cell[2], "','", cell[3], "','", cell[0], "')\" name='button' class='btn' value='确定'><input type='button' onclick=\"util.Cancle('", cell[0], "')\" name='button' class='btn' value='取消'></div>");
                    return ops.join("");
                }
                function processOp(value, cell) {

                    var ops = [];
                    ops.push("&nbsp;<a id='d_", cell[0], "' title='详情' href='javascript:;'  onclick=\"util.Detail('", cell[2], "','", cell[3], "','", cell[0], "')\">详情▼</a>");
                    ops.push("&nbsp;<a title='回复' href='javascript:;'  onclick=\"util.Reply('", value, "')\">回复</a>");
                    ops.push("&nbsp;<a title='删除' href='javascript:;'  onclick=\"util.Delete('", cell[2], "','", cell[3], "')\">删除</a>");
                    return ops.join("");
                }
                //回复
                util.Reply = function (id) {

                    $("#Reply_" + id).slideDown();

                };

                util.Cancle = function (id) {

                    $("#Reply_" + id).slideUp();
                    $("#Reply_" + id).children("textarea").val("");
                }

                util.Submit = function (mid, rid, id) {
                    //alert(id + " " + value);
                    var content = $("#Reply_" + id).children("textarea").val();
                    if (content.trim() != "") {
                        $.post("/UserDetails/AddMesssages",
                            {
                                m_id: mid, r_id: rid, content: content
                            }, function (data) {
                                if (data.Status > 0) {
                                    $.dialog.tips(data.Message, 1, 'tips.gif', function () {
                                        window.location.href = data.Data;
                                    });
                                }
                                else {
                                    $.dialog.tips(data.Message, 1, 'tips.gif');
                                }
                            })
                    }
                    else {
                        $.dialog.tips("回复内容不允许为空！", 1, 'tips.gif');
                    }
                }

                var cc = false;
                util.Detail = function (mid, rid, id) {
                    if (!cc) {
                        cc = true;
                        $("#d_" + id).html("收起▲");
                        $.post("/UserDetails/MessageDetail", { m_id: mid, r_id: rid }, function (json) {
                            var html = "";
                            for (var i = 0; i < json.length; i++) {
                                //alert(json[i].Message);
                                var second = json[i].AddTime.substring(6, json[i].AddTime.indexOf(')'));
                                html = html + "&emsp;&emsp;&emsp;&emsp;来自<b style='color:red'>" + json[i].Name + "</b>的消息：<b style='color:blue'>" + json[i].Message + "</b>[" + new Date(parseInt(second)).toLocaleString() + "]</br></br>";
                            }
                            $("#Detail_" + id).html(html).slideDown();
                        })
                    } else {
                        $("#Detail_" + id).slideUp();
                        cc = false;
                        $("#d_" + id).html("详情▼");
                    }
                }

                util.Flag = function (id) {
                    $.post("/UserDetails/UpdateMessageStatus", { id: id }, function (data) {
                        if (data.Status > 0) {
                            $.dialog.tips(data.Message, 1, 'tips.gif', function () {
                                window.location.href = data.Data;
                            });
                        }
                        else {
                            $.dialog.tips(data.Message, 1, 'tips.gif');
                        }
                    })
                }

                util.Delete = function (mid, rmid) {
                    $.dialog.confirm('确定删除该会话吗？', function () {
                        $.post("/UserDetails/DeleteMessage", { mid: mid, rmid: rmid }, function (data) {
                            if (data.Status > 0) {
                                $.dialog.tips(data.Message, 1, 'tips.gif');
                                location.href = data.Data;
                            } else {
                                $.dialog.tips(data.Message, 1, 'tips.gif');
                            }
                        })
                    });
                }

            });
        })(window, undefined, jQuery);
        var util = {};
        var options = {
            listUrl: "@Url.Action("MessageList")"

        };
    </script>
}

<div class="RightContrent">
    <div style="margin-left: 50px; margin-right: 50px;">
        <div class="tab-content">
            <div class="line10"></div>
            <div class="line10"></div>
            <div class="tab_title">@ViewBag.Title</div>
            <div class="tab-content">
                <div style="width: 16px; height: 12px; float: left;">
                    <img src="~/Content/Images/leftarraw.png" />
                </div>
            </div>

            <div class="tab-content_border">

                <div class="u-center">
                    @*  <input type="hidden" name="ID" id="hidMid" value="@Model.ID" >*@
                    <div class="menu-list" align="right">
                        <a href="/UserDetails/SendMessage" class="btn" style="color: white">发私信</a>
                    </div>

                    <div class="line10"></div>
                    <div id="gridlist">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
